package cqrtplm.controller;

import com.ty.basic.response.ResponseResult;
import cqrtplm.dto.DrawingInfoDTO;
import cqrtplm.dto.OaUploadFileDTO;
import cqrtplm.dto.PartNumberDTO;
import cqrtplm.service.RtOaFormMappingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/rest/v1")
public class OAFromController {

    @Resource
    private RtOaFormMappingService rtOaFormMappingService;

    @PostMapping("/ratoChangeNotice")
    public ResponseResult ratoChangeNotice(@RequestParam("file") MultipartFile file,
                                           @RequestParam("workFlowContainerId") String workFlowContainerId) {
        log.info(">>>OAFromController>>>>>ratoChangeNotice>>>>{}", workFlowContainerId);
        try {
            rtOaFormMappingService.rotaChangeNotice(file, workFlowContainerId);
        } catch (IOException e) {
            return ResponseResult.fail("200", e.getMessage());
        }
        return ResponseResult.success();
    }


    @PostMapping("/queryEBOMPartByNumber")
    public ResponseResult queryEBOMPartByNumber(@RequestBody PartNumberDTO partNumberDTO) {
        log.info(">>>OAFromController>>>>>queryPartByNumber>>>>{}", partNumberDTO);
        List<DrawingInfoDTO> drawingInfoDTOS = rtOaFormMappingService.queryEBOMPartByNumber(partNumberDTO);
        log.info(">>>OAFromController>>>>>drawingInfoDTOS>>>>{}", drawingInfoDTOS);
        return ResponseResult.success(drawingInfoDTOS);
    }

    @PostMapping("/queryPatternCodePartByNumber")
    public ResponseResult queryPatternCodePartByNumber(@RequestBody PartNumberDTO partNumberDTO) {
        log.info(">>>OAFromController>>>>>queryPatternCodePartByNumber>>>>{}", partNumberDTO);
        return ResponseResult.success(rtOaFormMappingService.queryPatternCodePartByNumber(partNumberDTO));
    }

    @PostMapping("/uploadFile")
    public ResponseResult uploadFile(@RequestBody OaUploadFileDTO oaUploadFileDTOS) {
        log.info(">>>OAFromController>>>>>uploadFile>>>>{}", oaUploadFileDTOS);
        rtOaFormMappingService.uploadFile(oaUploadFileDTOS);
        return ResponseResult.success();
    }


}
